<?
if($_POST['action']){
$fileupload=$_FILES['fileupload']['tmp_name'];
$fileupload_name=$_FILES['fileupload']['name'];
$fileupload_size=$_FILES['fileupload']['size'];
$fileupload_type=$_FILES['fileupload']['type'];
	if($fileupload){
		//	$sql = "delete from tb_detail";
//			$qr = mysql_query($sql);
//			$sql = "ALTER TABLE  `tb_detail` AUTO_INCREMENT =1";
//			$qr = mysql_query($sql);
			require_once '../Classes/PHPExcel/IOFactory.php';
			$objPHPExcel = PHPExcel_IOFactory::load($fileupload);
			foreach ($objPHPExcel->getWorksheetIterator() as $worksheet) {
                $worksheetTitle     = $worksheet->getTitle();
                $highestRow         = $worksheet->getHighestRow(); // e.g. 10
                $highestColumn      = $worksheet->getHighestColumn(); // e.g 'F'
                $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
                $nrColumns = ord($highestColumn) - 64;
				
                for ($row = 2; $row <= $highestRow; ++ $row) {
					
                        $cell = $worksheet->getCellByColumnAndRow(0, $row);
                       	$membershipId = $cell->getValue();
						
						$cell1 = $worksheet->getCellByColumnAndRow(1, $row);
                        $sendDate = $cell1->getValue();
						
						$cell2 = $worksheet->getCellByColumnAndRow(2, $row);
                        $protectionStart = $cell2->getValue();
						
						$cell3 = $worksheet->getCellByColumnAndRow(3, $row);
                        $receiptNo = $cell3->getValue();
						
						$cell4 = $worksheet->getCellByColumnAndRow(4, $row);
                       	$company = $cell4->getValue();
						
						$cell5 = $worksheet->getCellByColumnAndRow(5, $row);
                        $insureType = $cell5->getValue();
						
						$cell6 = $worksheet->getCellByColumnAndRow(6, $row);
                        $postcode= $cell6->getValue();
						
						$cell7 = $worksheet->getCellByColumnAndRow(7, $row);
                        $customerName = $cell7->getCalculatedValue();
						
						$cell8 = $worksheet->getCellByColumnAndRow(8, $row);
                        $insureBudget = $cell8->getValue();
						
						$cell9 = $worksheet->getCellByColumnAndRow(9, $row);
                        $insureNet = $cell9->getValue();
						
						$cell10 = $worksheet->getCellByColumnAndRow(10, $row);
                        echo $insureTotal = $cell10->getValue();
		
						//insert data//
						$data = array(
						"membershipId"=>$membershipId,
						"sendDate"=>PHPExcel_Shared_Date::ExcelToPHP($sendDate),
						"protectionStart"=>PHPExcel_Shared_Date::ExcelToPHP($protectionStart),
						"receiptNo"=>$receiptNo,
						"company"=>$company,
						"insureType"=>$insureType,
						"postcode"=>$postcode,
						"customerName"=>$customerName,
						"insureBudget"=>$insureBudget,
						"insureNet"=>round($insureNet,2),
						"insureTotal"=>$insureTotal,
						
						);
						if($membershipId<>''){
							if($_POST['action']==1)
							{
								insert("tb_report",$data);
								$prefix = 'report';
							}else{
								insert("tb_expire",$data);
								$prefix = 'expire';
							}
						}	
						//end insert//
				}
			}
	
	}	
	?>					
	<SCRIPT LANGUAGE="JavaScript">alert("update content suscessfully");window.location='admin.php?page=<?=$prefix;?>';</script>						
	<?php					
}//end $_POST[action]//

?>
   